package top.zhangjianyong.tools.constant;

import top.zhangjianyong.tools.model.MealConfig;

import java.time.LocalDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

public enum CanteenAccount {

    BEN_BEN("20211107", "520520", "笨笨", 2, true),
    DOU_DOU("20221237", "112464", "豆豆", 1, false);

    static {
        //添加配置
        BEN_BEN.mealConfig.add(new MealConfig(CanteenMeal.HAMBURGER, 2, "2"));
        BEN_BEN.mealConfig.add(new MealConfig(CanteenMeal.NOODLE_NO_JTM, 99, "2"));
        BEN_BEN.mealConfig.add(new MealConfig(CanteenMeal.TAOCAN_E, 99, "2"));

        BEN_BEN.mealConfig.add(new MealConfig(CanteenMeal.TAOCAN_C, 3, "3"));
        BEN_BEN.mealConfig.add(new MealConfig(CanteenMeal.TAOCAN_D, 99, "3"));
        //添加配置
        DOU_DOU.mealConfig.add(new MealConfig(CanteenMeal.TAOCAN_E, 99, "2"));
        DOU_DOU.mealConfig.add(new MealConfig(CanteenMeal.TAOCAN_C, 99, "3"));
    }

    public final String userName;
    public final String password;
    public final String realName;
    public final int dayOfWeek;
    public final boolean open;
    public final List<MealConfig> mealConfig;


    CanteenAccount(String userName, String password, String realName, int dayOfWeek, boolean open) {
        this.userName = userName;
        this.password = password;
        this.realName = realName;
        this.dayOfWeek = dayOfWeek;
        this.open = open;
        this.mealConfig = new ArrayList<>();
    }

    public static List<CanteenAccount> getAllAccount() {
        return Arrays.stream(values())
                .filter(account -> account.open)
                .collect(Collectors.toList());
    }

    public static List<CanteenAccount> getAllByDayOfWeek(int dayOfWeek) {
        return getAllAccount().stream()
                .filter(account -> account.open)
                .filter(account -> account.dayOfWeek == dayOfWeek)
                .collect(Collectors.toList());
    }

    public void reset() {
        this.mealConfig.stream().forEach(MealConfig::reset);
    }

    public static void resetAll() {
        getAllAccount().stream().forEach(CanteenAccount::reset);
    }

    public static CanteenAccount getOneByDayOfWeek(int dayOfWeek) {
        return getAllByDayOfWeek(dayOfWeek).stream().findFirst().orElse(null);
    }

    public static void main(String[] args) {
        System.out.println(LocalDateTime.now().getDayOfWeek().getValue());
    }
}
